{layout name="layout" /}
<!-- 引入layui -->
<script src="/static/frontend/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<style>
    .title {
        font-size: 20px;
        margin: 20px;
        text-align: center;
    }
    .author,.time {
        text-align: center;
    }
    .all-comment {
        margin: 10px auto;
        text-align: center;
    }
    .comment {
        margin: 5px auto;
    }
</style>
<div class="center-content">
    <div class="title">
        {$title}
    </div>
    <div class="content">
        {:htmlspecialchars_decode($content)}
    </div>
    <div class="author">
        作者：{$author}
    </div>
    <div class="time">
        创建时间：{$createTime}
    </div>
    <div class="time">
        更新时间：{$updateTime}
    </div>
</div>

<form class="layui-form" method="post" action="">
    <input type="hidden" name="id" value="{$id}">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">评论</label>
        <div class="layui-input-block">
            <textarea name="comment" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>

<div class="all-comment">
    {if (!empty($articleComment))}
    {foreach $articleComment as $k=>$v}
    <div class="comment">
        <div>作者：{$v['author']}</div>
        <div>评论：<br>{$v['content']}</div>
        <div>发布时间：{$v['create_time']}</div>
        <div>更新时间：{$v['update_time']}</div>
    </div>
    {/foreach}
    {/if}
</div>

<script>
    layui.use('form', function(){
        var form = layui.form,
        $ = layui.jquery;

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.post('/frontend/all-article/submit-comment', data.field, function (res) {
                if (res.code == 0) {
                    // 提交成功
                    layer.msg(res.msg, {
                        icon:1,
                        time: 1000
                    },function () {
                        // 重新加载父页面
                        location.reload();
                    });
                } else if (res.code == 302) {
                    location.href = '/frontend/error/' + res.msg;
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });
    });
</script>